package cc.laop.mq.kafka.producer;

import cc.laop.mq.utils.ApplicationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;

/**
 * Created by Pengpeng on 2017/5/26.
 */
public class Producer {

    private static final Logger logger = LoggerFactory.getLogger(Producer.class);

    public static void main(String[] args) throws IOException, InterruptedException {
        new Thread(() -> {
            logger.info("Producer starting...");
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext
                    ("classpath:spring/spring-kafka-producer.xml");
            context.start();
            logger.info("Producer started.");
        }).start();


        //while (true) {
        //    Scanner scanner = new Scanner(System.in);
        //    String message = scanner.nextLine();
        //}
        Thread.sleep(10000);
        for (int i = 0; i < 1000; i++) {
            ProducerServer server = (ProducerServer) ApplicationUtils.getBean(ProducerServer.class);
            server.sned("topic-" + i % 2, i, false, 0, "admin");
            Thread.sleep(2000);
        }
    }

}
